package org.cybzacg.convert.model;

import org.cybzacg.convert.enums.RegistrationStatus;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 注册统计信息
 */
public class RegistrationStatistics {
    private final List<String> scannedPackages;
    private final int totalFound;
    private final int successCount;
    private final int failureCount;
    private final int skippedCount;
    private final long durationMs;
    private final List<RegistrationResult> results;

    public RegistrationStatistics(List<String> scannedPackages, int totalFound, int successCount,
                                  int failureCount, int skippedCount, long durationMs, List<RegistrationResult> results) {
        this.scannedPackages = new ArrayList<>(scannedPackages);
        this.totalFound = totalFound;
        this.successCount = successCount;
        this.failureCount = failureCount;
        this.skippedCount = skippedCount;
        this.durationMs = durationMs;
        this.results = new ArrayList<>(results);
    }

    public List<String> scannedPackages() {
        return new ArrayList<>(scannedPackages);
    }

    public List<RegistrationResult> results() {
        return new ArrayList<>(results);
    }

    public List<RegistrationResult> getSuccessfulResults() {
        return results.stream()
                .filter(r -> r.status() == RegistrationStatus.SUCCESS)
                .toList();
    }

    public List<RegistrationResult> getFailedResults() {
        return results.stream()
                .filter(r -> r.status() == RegistrationStatus.FAILURE)
                .toList();
    }

    public List<RegistrationResult> getSkippedResults() {
        return results.stream()
                .filter(r -> r.status() == RegistrationStatus.SKIPPED)
                .toList();
    }

    @NotNull
    @Override
    public String toString() {
        return String.format(
                "RegistrationStatistics{扫描包=%s, 发现=%d, 成功=%d, 失败=%d, 跳过=%d, 耗时=%dms}",
                scannedPackages, totalFound, successCount, failureCount, skippedCount, durationMs);
    }
}
